import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import store from '@/store'
import routes from './routes'
import {
    beforeEachCB
} from './permission'

const router = new Router({
    scrollBehavior: () => ({
        y: 0
    }),
    routes
})

//开启前置守卫
router.beforeEach(beforeEachCB.bind(router));

//处理跳转导航时的内部错误.在Router原型上为其push函数添加捕捉错误的catch函数
const routerPush = Router.prototype.push;
Router.prototype.push = to => routerPush.call(router, to).catch(err => err);

export default router